package com.wl.mr.group;

import com.wl.mr.partition.CustomPartitioner;
import com.wl.mr.partition.PartitionBean;
import com.wl.mr.partition.PartitionMapper;
import com.wl.mr.partition.PartitionReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class GroupDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "GroupDriver");

        job.setMapperClass(GroupMapper.class);
        job.setReducerClass(GroupReducer.class);

        job.setMapOutputKeyClass(GroupBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(GroupBean.class);
        job.setOutputValueClass(NullWritable.class);

        job.setPartitionerClass(GroupPartitioner.class);
        job.setNumReduceTasks(3);

        job.setGroupingComparatorClass(ordGroupingComparator.class);

        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);
    }
}
